'''
1.显示功能界面

'''


def info_print():
    print('请选择功能')
    print('1.添加')
    print('2.删除')
    print('3.修改')
    print('4.查询')
    print('5.显示')
    print('6.退出')
    print('-' * 20)


def add_info():
    '''添加函数'''
    user_id = input('请输入学号:')
    user_name = input('请输入姓名:')
    user_tel = input('请输入手机号:')
    global info
    for i in info:
        if i['name'] == user_name:
            print('姓名已经存在，请重新输入')
            return
    info_dict = {}
    info_dict['id'] = user_id
    info_dict['name'] = user_name
    info_dict['tel'] = user_tel
    info.append(info_dict)
    print(info)


def del_info():
    user_name = input('请输入需要删除学员的姓名：')
    global info
    for i in info:
        if i['name'] == user_name:
            del i[user_name]
            print('删除成功')
            break
    else:
        # for else遍历所有后，打印结果。
        print(f'学员姓名{user_name}不存在！')
    print(info)


def update_user():
    user_name = input('请输入需要修改学员的姓名：')
    global info
    for i in info:
        if i['name'] == user_name:
            user_id = input('请输入修改的学号:')
            user_tel = input('请输入修改的号码:')
            i['id'] = user_id
            i['tel'] = user_tel
            print('修改成功')
            break
    else:
        # for else遍历所有后，打印结果。
        print(f'学员姓名{user_name}不存在！')
    print(info)


def query_info():
    user_name = input('请输入查找学员的姓名：')
    global info
    for i in info:
        if i['name'] == user_name:
            print(f"学员姓名{i['user_name']}，id为{i['id']},手机号为{i['tel']}")
            break
    else:
        print('查询的人员不存在！')

def print_info():
    print('学号\t姓名\t手机号\t')
    for i in info:
        print(f"{i['id']}\t{i['name']}\t{i['tel']}")



info = []
while True:
    info_print()

    user_num = int(input('请输入功能序号：'))

    if user_num == 1:
        # print('添加')
        add_info()
    elif user_num == 2:
        # print('删除')
        del_info()
    elif user_num == 3:
        # print('修改')
        update_user()
    elif user_num == 4:
        # print('查询')
        query_info()
    elif user_num == 5:
        print_info()
    elif user_num == 6:
        #print('退出')
        exit_flag=input('确定要退出吗？(Y/N):').upper()
        print(exit_flag)
        if exit_flag=='Y':
            break
    else:
        print('输入有误，请重新输入：')
